<?php
namespace App\Http\Controllers\AppApi\My;

use App\Services\Admin\StaffService;
use App\Utilities\Upload;
use Illuminate\Http\Request;
use Hash;

class StaffController extends BaseController
{
    /**
     * 员工接口控制器
     * 制作者：九哥
     */

    protected $service;

    public function __construct()
    {
        parent::__construct();
        $this->service = new StaffService();
    }

    /**
     * 获取员工信息
     */
    public function getBasicInfo(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($type,[1,2,3,4])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $model = $this->service->getOneByUid($uid);
        if (!$model) { return $this->toJson(-3); }
        $dataArr = array(
            'realname' => $model->realname,
            'sex' => $model->sex,
            'birthName' => $model->birthday,
            'eduName' => $this->service->getEduName($model->education),
            'weight' => $model->weight,
//            'polity' => $model->political_status,
            'polityName' => $this->service->getPolityName($model->political_status),
            'nativePlace' => $model->native_place,
            'nation' => $model->nationality,
            'marryName' => $this->service->getMarryName($model->marriage),
            'idcard' => $model->idcard,
            'house' => $model->house,
            'image' => file_exists(ltrim($model->image)) ? $model->image : '',
            'houseAddress' => $model->household_address,
            'liveAddress' => $model->residential_address,
            'contactPerson' => $model->contact_person,
            'contactPhone' => $model->contact_phone,
            'salary' => $model->salary,
            'skillStr' => $model->skill,
            'skillNames' => $this->service->getSkills($uid),
            'hobbyStr' => $model->hobby,
            'hobbyNames' => $this->service->getHobbys($uid),
        );
        return $this->toJson(0,$dataArr);
    }

    /**
     * 获取扩展信息
     */
    public function getExtInfo(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $type = $request->type;
        $cate = $request->cate;
        if (!$token || !in_array($type,[1,2,3,4])) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $model = $this->service->getOptionByUid($uid);
        if (!$model) { return $this->toJson(-3); }
        $dataArr = array(
            'eduBgs' => $model['eduBgs'],
            'workHistorys' => $model['workHistorys'],
            'familys' => $model['familys'],
            'comments' => $model['comments'],
            'files' => $this->service->getComFile($uid),
        );
        return $this->toJson(0,$dataArr);
    }
}